package com.own.business.selasticsearch.business.entity.vo;

import co.elastic.clients.elasticsearch.indices.stats.IndicesStats;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * IndexManagementIndicesVo
 *
 * @author chenxueli
 * @date 2024-05-08 12:57:00
 */
@Data
@NoArgsConstructor
public class IndexManagementIndicesVo implements Serializable {

    @Schema(title = "uuid")
    private String uuid;

    @Schema(title = "索引名称")
    private String indexName;

    @Schema(title = "健康状态")
    private String health;

    @Schema(title = "状态")
    private String status;

    @Schema(title = "分片数量")
    private Integer replicas;

    @Schema(title = "文档数量")
    private Integer docsCount;

    @Schema(title = "存储大小（byte）")
    private Long storageSize;

    @SuppressWarnings("all")
    public IndexManagementIndicesVo(String name, IndicesStats stats) {
        this.uuid = stats.uuid();
        this.indexName = name;
        this.health = stats.health().toString();
        this.status = stats.status().toString();
        this.replicas = 1;
        this.docsCount = (int) stats.total().docs().count();
        this.storageSize = stats.total().store().sizeInBytes();
    }

}
